package com.alex.springbootdemo.database.migrator;


import com.alex.springbootdemo.mapper.mbg.UmsRoleMapper;
import com.alex.springbootdemo.model.pojo.UmsRole;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
@AllArgsConstructor
@Slf4j
public class Migrator1 {
    /**
     * 初始化角色表
     */

    private final UmsRoleMapper umsRoleMapper;


    public void run(){
        List<UmsRole> umsRoles = umsRoleMapper.selectAll();
        umsRoles.forEach(elem->umsRoleMapper.deleteByPrimaryKey(elem.getId()));

        List<UmsRole> list = Lists.newArrayList();
        UmsRole umsRole1 = new UmsRole();
        umsRole1.setName("商品管理员")
                .setDescription("商品管理员")
                .setAdminCount(0)
                .setCreateTime(new Date());

        UmsRole umsRole2 = new UmsRole();
        umsRole2.setName("商品分类管理员")
                .setDescription("商品分类管理员")
                .setAdminCount(0)
                .setCreateTime(new Date());

        UmsRole umsRole3 = new UmsRole();
        umsRole3.setName("商品类型管理员")
                .setDescription("商品类型管理员")
                .setAdminCount(0)
                .setCreateTime(new Date());

        UmsRole umsRole4 = new UmsRole();
        umsRole4.setName("品牌管理员")
                .setDescription("品牌管理员")
                .setAdminCount(0)
                .setCreateTime(new Date());
        list.add(umsRole1);
        list.add(umsRole2);
        list.add(umsRole3);
        list.add(umsRole4);

        list.forEach(umsRoleMapper::insertSelective);
    }





}
